import 'package:example/arg/demo3arg.dart';
import 'package:example/router/example_route.dart';
import 'package:example/router/example_routes.dart';
import 'package:example_package/example_package.dart';
import 'package:example_package1/example_package1.dart';
import 'package:flutter/material.dart';
import 'package:riki_router/riki_router.dart';

void main() {
  final RikiRouterDelegate _routeDelegate = RikiRouterDelegate(
    getRouteSettings: getRouteSettings,
  );
  RikiRouter.instance.init(
    _routeDelegate,
  );
  RikiRouter.instance.expandConvert(<T extends Object?>(dynamic value) {
    if (Demo3Arg.fromJson({}) is T && value is Map<dynamic, dynamic>) {
      return Demo3Arg.fromJson(value) as T;
    }
    return null;
  });
  runApp(MyApp());
}

class MyApp extends StatelessWidget implements RikiEventListener {
  MyApp() {
    ExamplePackage.instance.init();
    ExamplePackage1.instance.init();
    RikiEvent.instance.addListener('MAIN', this);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      title: 'Riki Route Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      routerDelegate: RikiRouter.instance.routerDelegate,
      routeInformationParser: RikiRouter.instance.routeInformationParser,
    );
  }

  @override
  void onRikiEvent(RikiEventType type, arguments,callback) {
    print('主工程监听：$type，$arguments');
  }

  @override
  List<String> get registerEvents => [];
}
